package com.bree.erp.entity;

import java.util.Map;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MapKeyColumn;
import javax.persistence.MapKeyEnumerated;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

@NamedQuery(name=Supplier.QUERY_SELECT_ALL_SUPPLIER, query="SELECT s FROM Supplier s")
@Entity
public class Supplier {
	
	public static final String QUERY_SELECT_ALL_SUPPLIER = "findAllSupplier";

	public static final int COL_NAME_LEN = 50;
	public static final int COL_REMARKS_LEN = 255;
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@Column(length=COL_NAME_LEN)
	private String name;

	@Column(length=COL_REMARKS_LEN)
	private String remarks;
	
	@OneToOne
	private Currency currency;
	
	@ElementCollection
	@CollectionTable(name="SUPPLIER_PHONE")
	@MapKeyEnumerated(EnumType.STRING)
	@MapKeyColumn(name="PHONE_TYPE")
	@Column(name="PHONE_NUM")
	private Map<PhoneType, String> phoneNumbers;
	
	@Embedded
	private Address address;
	
	@Override
	public boolean equals(Object object) {
		
		if(object instanceof Supplier) {
			if(this.id != null) {
				Supplier that = (Supplier) object;
				return this.id.equals(that.id);
			}
		}
			
		
		return false;
	}
	
	@Override
	public int hashCode() {
		return this.id == null ? 0 : this.id.hashCode();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the phoneNumbers
	 */
	public Map<PhoneType, String> getPhoneNumbers() {
		return phoneNumbers;
	}

	/**
	 * @param phoneNumbers the phoneNumbers to set
	 */
	public void setPhoneNumbers(Map<PhoneType, String> phoneNumbers) {
		this.phoneNumbers = phoneNumbers;
	}

	/**
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

	/**
	 * @return the remarks
	 */
	public String getRemarks() {
		return remarks;
	}

	/**
	 * @param remarks the remarks to set
	 */
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	/**
	 * @return the currency
	 */
	public Currency getCurrency() {
		return currency;
	}

	/**
	 * @param currency the currency to set
	 */
	public void setCurrency(Currency currency) {
		this.currency = currency;
	}
	
	
}
